var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0}),
    (o.EAnalyticsEventType = o.EAnalyticsEvent = o.EAnalyticsSDKType = void 0);
var n,
    a,
    i = e("CocosAnalyticsPack"),
    r = e("md5"),
    s = cc._decorator,
    l = s.ccclass;
s.property,
    (function (e) {
        e[(e.CoCos = 0)] = "CoCos";
    })((n = o.EAnalyticsSDKType || (o.EAnalyticsSDKType = {}))),
    (function (e) {
        (e[(e.Start = 0)] = "Start"),
            (e[(e.Success = 1)] = "Success"),
            (e[(e.Fail = 2)] = "Fail"),
            (e[(e.Cancel = 3)] = "Cancel");
    })(o.EAnalyticsEvent || (o.EAnalyticsEvent = {})),
    (function (e) {
        (e[(e.Custom = 0)] = "Custom"), (e[(e.Level = 1)] = "Level");
    })((a = o.EAnalyticsEventType || (o.EAnalyticsEventType = {})));
var c = (function () {
    function e() {
        var e;
        (this.channelType = (((e = {})[cc.sys.OPPO_GAME] = "oppo"), (e[cc.sys.VIVO_GAME] = "vivo"), e)),
            (this.type = n.CoCos),
            (this.enableDebug = !0),
            (this.analyticsPack = null),
            (this.userId = ""),
            (this.userId = this._getUserId());
    }
    var t;
    return (
        (t = e),
        (e.getInstance = function () {
            return null == t.instance && (t.instance = new t()), t.instance;
        }),
        (e.prototype.init = function (e) {
            switch (((this.type = e), cc.log("统计开始初始化"), this.type)) {
                case n.CoCos:
                    this.analyticsPack = new i.default();
                    break;
                default:
                    return void cc.error("not find analytics");
            }
            var t = this.channelType[cc.sys.platform];
            (t = t || "unknow"),
                this.analyticsPack.enableDebug(this.enableDebug),
                this.analyticsPack.init({channel: t, userId: this.userId});
        }),
        (e.prototype.login = function (e, t) {
            this.analyticsPack && this.analyticsPack.login(e, t);
        }),
        (e.prototype.raiseCustomEvent = function (e, t) {
            this.analyticsPack && this.analyticsPack.raiseEvent(a.Custom, e, t.name, t);
        }),
        (e.prototype.raiseLevelEvent = function (e, t) {
            this.analyticsPack && this.analyticsPack.raiseEvent(a.Level, e, t.level, t);
        }),
        (e.prototype._getUserId = function () {
            var e = cc.sys.localStorage.getItem("analytics_userId");
            if (e) return e;
            var t = new Date().getTime(),
                o = this.randomStr(10) + t.toString(),
                n = new r.Md5();
            n.start(), n.appendStr(o);
            var a = n.end();
            return cc.log(a), cc.sys.localStorage.setItem("analytics_userId", a), a;
        }),
        (e.prototype.randomStr = function (e) {
            for (var t = "", o = 0; o < e; o++) {
                var n = Math.floor(36 * Math.random()) + 0;
                t += n <= 9 ? n : String.fromCharCode("a".charCodeAt(0) + n - 10);
            }
            return t;
        }),
        (e.instance = null),
        (t = __decorate([l], e))
    );
})();
o.default = c;
